﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PongGame
{
    class GameManager
    {
        Vector2 ballPosition = new Vector2(0.5f, 0.5f);
        float leftPaddlePosition , rightPaddlePosition;
        int leftPlayerLives, rightPlayerLives;
        bool multiplayer = false;
        Vector2 ballSpeedVector = new Vector2(0, 0);// set to Zero when in menu or game over.
        const float ComputerPaddleSpeed = .5f;
        const float BallSpeedMultiplicator = 0.5f;

        public void StartGame()
        {
            leftPlayerLives = 3;
            rightPlayerLives = 3;
            leftPaddlePosition = 0.5f;// 0 means top, 1 means bottom.
            rightPaddlePosition = 0.5f;
            StartNewBall();
        }

        public void StartNewBall()
        {
            ballPosition = new Vector2(0.5f, 0.5f);//Middle of the screen
            Random rnd = new Random((int)DateTime.Now.Ticks);
            int direction = rnd.Next(4);
            ballSpeedVector =
                direction == 0 ? new Vector2(1, 0.8f) :
                direction == 1 ? new Vector2(1, -0.8f) :
                direction == 2 ? new Vector2(-1, 0.8f) :
                new Vector2(-1, -0.8f);
        }

        public void StopBall()
        {
            ballSpeedVector = new Vector2(0, 0);
        }

        void ShowLives()
        {
            // Support for both Windows monitors and TV screens on the Xbox 360!
            int xPos = 2;
            int yPos = 2;
#if XBOX360
			xPos += Window.ClientBounds.Width / 24;
			yPos += Window.ClientBounds.Height / 24;
#endif

        }

        //public void MovePaddle()
        //{
        //    // Move half way across the screen each second
        //    float moveFactorPerSecond = 0.5f *
        //        (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;

        //    // Move up and down if we press the cursor or gamepad keys.
        //    if (gamePadUp || keyboard.IsKeyDown(Keys.Up))
        //        rightPaddlePosition -= moveFactorPerSecond;

        //    if (gamePadDown || keyboard.IsKeyDown(Keys.Down))
        //        rightPaddlePosition += moveFactorPerSecond;

        //    if (multiplayer)
        //    {
        //        // Move up and down if we press the cursor or gamepad keys.
        //        if (gamePad2Up || keyboard.IsKeyDown(Keys.W))
        //            leftPaddlePosition -= moveFactorPerSecond;
        //        if (gamePad2Down || keyboard.IsKeyDown(Keys.S) || keyboard.IsKeyDown(Keys.O))
        //            leftPaddlePosition += moveFactorPerSecond;
        //    }
        //    else
        //    {
        //        // Just let the computer follow the ball position
        //        float computerChange = ComputerPaddleSpeed * moveFactorPerSecond;
        //        if (leftPaddlePosition > ballPosition.Y + computerChange)
        //            leftPaddlePosition -= computerChange;
        //        else if (leftPaddlePosition < ballPosition.Y - computerChange)
        //            leftPaddlePosition += computerChange;
        //    }
        //}
    }
}
